<template lang="pug">
//- 楼层编辑
el-dialog(:title="thisid==-1?'增加楼层':'编辑楼层'" :visible.sync="addfloor" :before-close="close" append-to-body)
    el-form(:v-model="f" label-position="right" label-width="80px")
        el-form-item.is-required(label="楼层名称" prop="name")
            el-input(v-model="f.name" auto-complete="off")
        el-form-item(label="是否启用")
            el-radio-group(v-model="showStatus")
                el-radio-button(:label="1") 不启用
                el-radio-button(:label="0") 启用
        el-form-item.is-required(label="选择店铺")
            el-select(v-model="shop" placeholder="选择相应店铺" :disabled="shopidlist")
                el-option(label="全部" value="0" v-if="shirott")
                el-option(v-for="item in opts" :key="item.shopId" :label="item.shopName" :value="item.shopId")
        el-form-item.is-required(label="排序" prop="sepc")
            el-input(v-model="f.sepc" auto-complete="off")
    .dialog-footer(slot="footer")
        el-button(@click="close") 取消
        el-button(type="primary" @click="save") 保存
</template>
<script>
    export default{
        props:['Position'],
        data(){
            return{
                addfloor:false,
                f:{},
                thisid:-1,
                shopidlist:false,
                showStatus:'0',
                opts:[],
                shirott:true,
                shop:'0'
            }
        },
        computed:{
            getstate(){
                return this.$store.state.floorclass;
            },
            getchange(){
                return this.$store.state.floorlist;
            }
        },
        watch:{
            getstate(v){
                this.addfloor=v
                this.getshop()
            },
            getchange(v){
                console.log(v.floorId)
                if(v.floorId){
                    this.f={}
                    this.f.name=v.floorName
                    this.f.sepc=v.sort
                    this.thisid=v.floorId
                    this.shop=v.shopId
                    this.showStatus=v.status
                }
            }
        },
        methods:{
            getshop(){//获取店铺
                if(this.$store.state.shiro){
                    this.opts=[].concat(this.$store.state.TOPshop)
                }else{
                    if(this.$store.state.TOPshopID!=''&&this.$store.state.TOPshopName!=''){
                        var shop={}
                        for(var i=0;i<this.$store.state.TOPshop.length;i++){
                            if(this.$store.state.TOPshop[i].shopId==this.$store.state.TOPshopID){
                                shop=this.$store.state.TOPshop[i]
                                this.opts.push(shop)
                                this.shop=this.$store.state.TOPshopID
                            }
                        }
                        this.shopidlist=true
                        this.shirott=false
                    }
                }
            },
            close(){//关闭弹窗,清空数据
                this.shop='0'
                this.showStatus='0'
                this.thisid=-1
                this.f={}
                this.$store.state.floorclass=false
                this.$store.state.floorlist={}
            },
            save(){//保存
                var _this=this
                var pa=new URLSearchParams()
                pa.append('floorName',this.f.name)
                pa.append('sort',this.f.sepc)
                pa.append('status',this.showStatus)
                pa.append('position',this.Position)
                pa.append('shopId',this.shop)
                if(this.thisid==-1){//新增
                    axios.get('/saveFloor.do',{params:pa}).then(r=>{
                        // console.log("新增楼层",r)
                        if(r.data.code==200){
                            _this.$message({
                                message:'添加成功',
                                type:'success'
                            })
                            _this.$store.state.floornew=false
                            _this.close()
                        }else{
                            _this.$message({
                                message:r.data.message,
                                type:'info'
                            })
                        }
                    })
                }else{//修改
                    pa.append('floorId',this.thisid)
                    axios.get('/updateFloorById.do',{params:pa}).then(r=>{
                        // console.log("修改楼层",r)
                        if(r.data.code==200){
                            _this.$message({
                                message:"修改成功",
                                type:'success'
                            })
                            _this.thisid=-1
                            _this.$store.state.floornew=false
                            _this.close()
                        }else{
                            _this.$message({
                                message:r.data.message,
                                type:'info'
                            })
                        }
                    })
                }
            }
        }
    }
</script>